package jfuzzyprincepless.zarchive.negotiation.protocols.propositionnetwork;

import jfuzzyprincepless.zarchive.algorithm.structure.ICommandConstruction;
import jfuzzyprincepless.zarchive.algorithm.structure.forcnstr.INegotiationFor;
import jfuzzyprincepless.zarchive.negotiation.protocols.INegotiationProtocol__Q_del;
import jfuzzyprincepless.negotiation.INegotiation;
import jfuzzyprincepless.negotiation.INegotiationContext;

public class DefaultExecForProtocol<E>
	implements INegotiationProtocol__Q_del
{
	private boolean separateFor;

	public DefaultExecForProtocol(boolean separateFor) {
		this.separateFor = separateFor;
	}

	public DefaultExecForProtocol() {
		this(false);
	}

	@SuppressWarnings("unchecked")
	@Override
	public INegotiation createNegotiation(
		ICommandConstruction construction,
		INegotiationContext context
	) {
		INegotiationFor<E> forLoop =
			(INegotiationFor<E>) construction;
		if (separateFor) {
			return ExecuteForNegotiation.newSeparateFor(forLoop);
		} else {
			return new ExecuteForNegotiation<E>(forLoop);
		}
	}
}
